home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 008 / src / hack.apply.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  5KB  |  184 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* hack.apply.c version 1.0.1 - "The flash awakens %s" (riv05!a3) */
  3.  
  4. #include    "hack.h"
  5. extern struct monst *bchit();
  6. extern struct obj *addinv();
  7. extern char pl_character[];
  8.  
  9. doapply() {
  10. register struct obj *obj;
  11.     obj = getobj("(", "use or apply");
  12.     if(!obj) return(0);
  13.     switch(obj->otyp){
  14.     case EXPENSIVE_CAMERA:
  15.         use_camera(obj); break;
  16.     case ICE_BOX:
  17.         use_ice_box(obj); break;
  18.     case MAGIC_WHISTLE:
  19.         if(pl_character[0] == 'W' || u.ulevel > 9) {
  20.             use_magic_whistle(obj);
  21.             break;
  22.         }
  23.         /* fall into next case */
  24.     case WHISTLE:
  25.         use_whistle(obj); break;
  26.     default:
  27.         pline("Sorry, I don't know how to use that.");
  28.         return(0);
  29.     }
  30.     return(1);
  31. }
  32.  
  33. /* ARGSUSED */
  34. use_camera(obj) /* register */ struct obj *obj; {
  35. register struct monst *mtmp;
  36.     if(!getdir()){
  37.         flags.move = multi = 0;
  38.         return;
  39.     }
  40.     if(mtmp = bchit(u.dx, u.dy, COLNO, '!')) {
  41.         if(mtmp->msleep){
  42.             mtmp->msleep = 0;
  43.             pline("The flash awakens %s.", monnam(mtmp));
  44.         } else
  45.         if(mtmp->data->mlet != 'y')
  46.         if(mtmp->mcansee || mtmp->mblinded){
  47.             register int tmp = dist(mtmp->mx,mtmp->my);
  48.             register int tmp2;
  49.             /* if(cansee(mtmp->mx,mtmp->my)) */
  50.               pline("%s is blinded by the flash!",Monnam(mtmp));
  51.             setmangry(mtmp);
  52.             if(tmp < 9 && !mtmp->isshk && !rn2(4))
  53.                 mtmp->mflee = 1;
  54.             if(tmp < 3) mtmp->mcansee  = mtmp->mblinded = 0;
  55.             else {
  56.                 tmp2 = mtmp->mblinded;
  57.                 tmp2 += rnd(1 + 50/tmp);
  58.                 if(tmp2 > 127) tmp2 = 127;
  59.                 mtmp->mblinded = tmp2;
  60.                 mtmp->mcansee = 0;
  61.             }
  62.         }
  63.     }
  64. }
  65.  
  66. struct obj *current_ice_box;    /* a local variable of use_ice_box, to be
  67.                 used by its local procedures in/ck_ice_box */
  68. in_ice_box(obj) register struct obj *obj; {
  69.     if(obj == current_ice_box ||
  70.         (Punished && (obj == uball || obj == uchain))){
  71.         pline("You must be kidding.");
  72.         return(0);
  73.     }
  74.     if(obj->owornmask & (W_ARMOR | W_RING)) {
  75.         pline("You cannot refrigerate something you are wearing.");
  76.         return(0);
  77.     }
  78.     if(obj->owt + current_ice_box->owt > 70) {
  79.         pline("It won't fit.");
  80.         return(1);    /* be careful! */
  81.     }
  82.     if(obj == uwep) {
  83.         if(uwep->cursed) {
  84.             pline("Your weapon is welded to your hand!");
  85.             return(0);
  86.         }
  87.         setuwep((struct obj *) 0);
  88.     }
  89.     current_ice_box->owt += obj->owt;
  90.     freeinv(obj);
  91.     obj->o_cnt_id = current_ice_box->o_id;
  92.     obj->nobj = fcobj;
  93.     fcobj = obj;
  94.     obj->age = moves - obj->age;    /* actual age */
  95.     return(1);
  96. }
  97.  
  98. ck_ice_box(obj) register struct obj *obj; {
  99.     return(obj->o_cnt_id == current_ice_box->o_id);
  100. }
  101.  
  102. out_ice_box(obj) register struct obj *obj; {
  103. register struct obj *otmp;
  104.     if(obj == fcobj) fcobj = fcobj->nobj;
  105.     else {
  106.         for(otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj)
  107.             if(!otmp->nobj) panic("out_ice_box");
  108.         otmp->nobj = obj->nobj;
  109.     }
  110.     current_ice_box->owt -= obj->owt;
  111.     obj->age = moves - obj->age;    /* simulated point of time */
  112.     (void) addinv(obj);
  113. }
  114.  
  115. use_ice_box(obj) register struct obj *obj; {
  116. register int cnt = 0;
  117. register struct obj *otmp;
  118.     current_ice_box = obj;    /* for use by in/out_ice_box */
  119.     for(otmp = fcobj; otmp; otmp = otmp->nobj)
  120.         if(otmp->o_cnt_id == obj->o_id)
  121.             cnt++;
  122.     if(!cnt) pline("Your ice-box is empty.");
  123.     else {
  124.         pline("Do you want to take something out of the ice-box? [yn] ");
  125.         if(readchar() == 'y')
  126.         if(askchain(fcobj, (char *) 0, 0, out_ice_box, ck_ice_box, 0))
  127.             return;
  128.         pline("That was all. Do you wish to put something in? [yn] ");
  129.         if(readchar() != 'y') return;
  130.     }
  131.     /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
  132.     otmp = getobj("0#%", "put in");
  133.     if(!otmp || !in_ice_box(otmp))
  134.         flags.move = multi = 0;
  135. }
  136.  
  137. struct monst *
  138. bchit(ddx,ddy,range,sym) register int ddx,ddy,range; char sym; {
  139.     register struct monst *mtmp = (struct monst *) 0;
  140.     register int bchx = u.ux, bchy = u.uy;
  141.  
  142.     if(sym) Tmp_at(-1, sym);    /* open call */
  143.     while(range--) {
  144.         bchx += ddx;
  145.         bchy += ddy;
  146.         if(mtmp = m_at(bchx,bchy))
  147.             break;
  148.         if(levl[bchx][bchy].typ < CORR) {
  149.             bchx -= ddx;
  150.             bchy -= ddy;
  151.             break;
  152.         }
  153.         if(sym) Tmp_at(bchx, bchy);
  154.     }
  155.     if(sym) Tmp_at(-1, -1);
  156.     return(mtmp);
  157. }
  158.  
  159. #include    "def.edog.h"
  160. /* ARGSUSED */
  161. use_whistle(obj) struct obj *obj; {
  162. register struct monst *mtmp = fmon;
  163.     pline("You produce a high whistling sound.");
  164.     while(mtmp) {
  165.         if(dist(mtmp->mx,mtmp->my) < u.ulevel*10) {
  166.             if(mtmp->msleep)
  167.                 mtmp->msleep = 0;
  168.             if(mtmp->mtame)
  169.                 EDOG(mtmp)->whistletime = moves;
  170.         }
  171.         mtmp = mtmp->nmon;
  172.     }
  173. }
  174.  
  175. /* ARGSUSED */
  176. use_magic_whistle(obj) struct obj *obj; {
  177. register struct monst *mtmp = fmon;
  178.     pline("You produce a strange whistling sound.");
  179.     while(mtmp) {
  180.         if(mtmp->mtame) mnexto(mtmp);
  181.         mtmp = mtmp->nmon;
  182.     }
  183. }
  184.